import { Controller, Get, Req, Request, Query, Headers, Session, Ip } from '@nestjs/common'
import { Request as ExpressRequest } from 'express'
@Controller("study")
export class StudyConstroller {
    @Get('NestJs')
    NestJs(@Req() req: ExpressRequest, age: number, @Request() request: ExpressRequest): string {
        console.log(req.url, request.method)
        return '学习nestjs'
    }

    // 参数装饰器Query获取请求参数
    @Get('getList')
    getList(@Query() query: any, @Query('id') id: string): string[] {
        console.log(query, id)
        return ['list01', 'list02', 'query id=' + id]
    }

    // 参数装饰器 请求头@Headers
    @Get('headers')
    getHeader(@Headers() headers: any, @Headers('accept') accept: any): string {
        console.log(headers)
        return accept
    }

    // 参数装饰器 会话 @Session   
    // 安装express-session依赖      main.ts注册app.use(ExpressSession,{})
    @Get("session")
    getSession(@Session() session: any):any {
        if(session.pageView){
            session.pageView++
        }else{
            session.pageView = 1;
        }
        console.log(session)
        return session
    }
    
    // IP 装饰器
    @Get("ip")
    getIp(@Ip() ip:any):any{
        console.log(ip);
        return ip
    }
}